package com.cleaningcloud.cld.controller.mini;

import com.cleaningcloud.cld.domain.*;
import com.cleaningcloud.cld.domain.dto.*;
import com.cleaningcloud.cld.domain.mini.AttStaffInfo;
import com.cleaningcloud.cld.domain.mini.HolidayData;
import com.cleaningcloud.cld.domain.mini.HolidayDto;
import com.cleaningcloud.cld.domain.vo.*;
import com.cleaningcloud.cld.service.ICldCalendarService;
import com.cleaningcloud.cld.service.mini.IMiniSalaryService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 工资管理 - 小程序接口
 */
@RestController
@RequestMapping("/mini/salary")
public class MiniSalaryController extends BaseController {

    @Autowired
    private IMiniSalaryService miniSalaryService;


    @Autowired
    private ICldCalendarService cldCalendarService;

    @Operation(description = "查询排休列表")
    @GetMapping("/selectHolidayList")
    public TableDataInfo selectHolidayList(HolidayDto holidayDto) {
        startPage();
        List<HolidayData> list = miniSalaryService.selectHolidayList(holidayDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "排休详情查看")
    @GetMapping("/getScheduleDetails")
    public AjaxResult getScheduleDetails(CldRestbreaksDto cldRestbreaksDto) {
        return success(miniSalaryService.getScheduleDetails(cldRestbreaksDto));
    }

    @Operation(description = "新增排休")
    @PostMapping("/addSchedule")
    public AjaxResult addSchedule(@RequestBody CldRestbreaksDto cldRestbreaks) {
        return toAjax(miniSalaryService.addSchedule(cldRestbreaks));
    }

    @Operation(description = "修改排休")
    @PostMapping("/updateSchedule")
    public AjaxResult updateSchedule(@RequestBody CldRestbreaksDto cldRestbreaks) {
        return toAjax(miniSalaryService.updateSchedule(cldRestbreaks));
    }

    @Operation(description = "查看加班列表")
    @GetMapping("/getWorkOvertimeList")
    public TableDataInfo getWorkOvertimeList(CldOvertimeDto cldOvertimeDto) {
        startPage();
        List<CldOvertimeVo> list = miniSalaryService.getWorkOvertimeList(cldOvertimeDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "审核加班列表查看")
    @GetMapping("/getAuditOvertimeList")
    public TableDataInfo getAuditOvertimeList(CldOvertimeDetailsDto cldOvertimeDetailsDto) {
        startPage();
        List<CldOvertimeDetailsVo> list = miniSalaryService.getAuditOvertimeList(cldOvertimeDetailsDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "加班详情查看")
    @GetMapping("/getWorkOvertimeDetails/{overTimeId}")
    public AjaxResult getWorkOvertimeDetails(@PathVariable Long overTimeId) {
        return success(miniSalaryService.getWorkOvertimeInfo(overTimeId));
    }

    @Operation(description = "加班详情明细查看")
    @GetMapping("/getWorkOvertimeDetails/getInfo")
    public AjaxResult getWorkOvertimeDetails(CldOvertimeDetailsVo cldOvertimeDetailsVo) {
        return success(miniSalaryService.getWorkOvertimeDetails(cldOvertimeDetailsVo));
    }

    @Operation(description = "审核加班详情查看")
    @GetMapping("/getAuditOvertimeDetails/{overtimeDetailsId}")
    public AjaxResult getAuditOvertimeDetails(@PathVariable Long overtimeDetailsId) {
        return success(miniSalaryService.getAuditOvertimeDetails(overtimeDetailsId));
    }

    @Operation(description = "新增加班")
    @PostMapping("/addWorkOvertime")
    public AjaxResult addWorkOvertime(@RequestBody CldOvertimeDto cldOvertimeDto) {
        return toAjax(miniSalaryService.addWorkOvertime(cldOvertimeDto));
    }

    @Operation(description = "加班打卡审核")
    @PutMapping("/auditWorkOvertime")
    public AjaxResult auditWorkOvertime(@RequestBody CldOvertimeDetails cldOvertimeDetails) {
        return toAjax(miniSalaryService.auditWorkOvertime(cldOvertimeDetails));
    }

    @Operation(description = "加班打卡修改")
    @PutMapping("/editWorkOvertimeCheck")
    public AjaxResult editWorkOvertimeCheck(@RequestBody CldAttendanceDto cldAttendanceDto) {
        return toAjax(miniSalaryService.editWorkOvertimeCheck(cldAttendanceDto.getOvertimeAttList()));
    }

    @Operation(description = "员工确认加班列表查看")
    @GetMapping("/getConfirmOvertimeList")
    public TableDataInfo getConfirmOvertimeList(CldOvertimeDetailsDto cldOvertimeDetailsDto) {
        startPage();
        List<CldOvertimeDetailsVo> list = miniSalaryService.getConfirmOvertimeList(cldOvertimeDetailsDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "员工确认加班提交")
    @PutMapping("/confirmWorkOvertime")
    public AjaxResult confirmWorkOvertime(@RequestBody CldOvertimeDetails cldOvertimeDetails) {
        return toAjax(miniSalaryService.confirmWorkOvertime(cldOvertimeDetails));
    }

    @Operation(description = "新增请假信息")
    @PostMapping("/addLeave")
    public AjaxResult addLeave(@RequestBody CldLeaveDto cldLeaveDto) {
        return toAjax(miniSalaryService.addLeave(cldLeaveDto));
    }

    @Operation(description = "请假列表查看")
    @GetMapping("/getLeaveList")
    public TableDataInfo getLeaveList(CldLeaveDto cldLeaveDto) {
        startPage();
        List<CldLeaveVo> list = miniSalaryService.getLeaveList(cldLeaveDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "请假信息审核")
    @PutMapping("/auditLeave")
    public AjaxResult auditLeave(@RequestBody CldLeaveDto cldLeaveDto) {
        return toAjax(miniSalaryService.auditLeave(cldLeaveDto));
    }

    @Operation(description = "请假详情查看")
    @GetMapping("/getLeaveDetails/{leaveId}")
    public AjaxResult getLeaveDetails(@PathVariable Long leaveId) {
        return success(miniSalaryService.getLeaveDetails(leaveId));
    }

    @Operation(description = "新增补卡信息")
    @PostMapping("/addReplacement")
    public AjaxResult addReplacement(@RequestBody CldReplaceDto cldReplaceDto) {
        return toAjax(miniSalaryService.addReplacement(cldReplaceDto));
    }

    @Operation(description = "补卡列表查看")
    @GetMapping("/getReplacementList")
    public TableDataInfo getReplacementList(CldReplaceDto cldReplaceDto) {
        startPage();
        List<CldReplaceVo> list = miniSalaryService.getReplacementList(cldReplaceDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "补卡信息审核")
    @PutMapping("/auditReplacement")
    public AjaxResult auditReplacement(@RequestBody CldReplaceDto cldReplaceDto) {
        return toAjax(miniSalaryService.auditReplacement(cldReplaceDto));
    }

    @Operation(description = "补卡详情查看")
    @GetMapping("/getReplacementDetails/{replaceId}")
    public AjaxResult getReplacementDetails(@PathVariable Long replaceId) {
        return success(miniSalaryService.getReplacementDetails(replaceId));
    }

    @Operation(description = "补卡页面班次加载")
    @GetMapping("/getClassesInfoMap")
    public AjaxResult getClassesInfoMap(@RequestBody CldClasses cldClasses) {
        return success(miniSalaryService.getClassesInfoMap(cldClasses));
    }

    @Operation(description = "奖惩记录列表查看")
    @GetMapping("/getRewardsList")
    public TableDataInfo getRewardsList(CldRewardsDto cldRewardsDto) {
        startPage();
        List<CldRewardsVo> list = miniSalaryService.getRewardsList(cldRewardsDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "新增奖惩记录")
    @PostMapping("/addRewards")
    public AjaxResult addRewards(@RequestBody CldRewardsDto cldRewardsDto) {
        return toAjax(miniSalaryService.addRewards(cldRewardsDto));
    }

    @Operation(description = "奖惩详情查看")
    @GetMapping("/getRewardsDetails/{rewardsId}")
    public AjaxResult getRewardsDetails(@PathVariable Long rewardsId) {
        return success(miniSalaryService.getRewardsDetails(rewardsId));
    }

    @Operation(description = "奖惩信息审核")
    @PutMapping("/auditRewards")
    public AjaxResult auditRewards(@RequestBody CldRewardsDto cldRewardsDto) {
        return toAjax(miniSalaryService.auditRewards(cldRewardsDto));
    }

    @Operation(description = "每日薪酬查看")
    @GetMapping("/selectDailySalary")
    public AjaxResult selectDailySalary(CldPayConfirm cldPayConfirm) {
        return success(miniSalaryService.selectDailySalary(cldPayConfirm));
    }

    @Operation(description = "每日薪酬确认")
    @PutMapping("/dailySalaryConfirmation")
    public AjaxResult dailySalaryConfirmation(@RequestBody CldPayConfirm cldPayConfirm) {
        return toAjax(miniSalaryService.dailySalaryConfirmation(cldPayConfirm));
    }

    @Operation(description = "薪酬列表查看")
    @GetMapping("/selectSalaryList")
    public TableDataInfo selectSalaryList(CldPayConfirmDto cldPayConfirm) {
        startPage();
        List<Map<String, Object>> list = miniSalaryService.selectSalaryList(cldPayConfirm);
        return getMiniDataTable(list);
    }

    @Operation(description = "薪酬明细查看")
    @GetMapping("/selectSalaryDetails")
    public AjaxResult selectSalaryDetails(CldPayConfirm cldPayConfirm) {
        List<Map<String, Object>> list = miniSalaryService.selectSalaryDetails(cldPayConfirm);
        return success(list);
    }

    @Operation(description = "查询考勤信息")
    @GetMapping("/getAttendanceInformation")
    public AjaxResult getAttendanceInformation(CldAttendanceDto cldAttendanceDto) {
        return success(miniSalaryService.getAttendanceInformation(cldAttendanceDto));
    }

    @Operation(description = "查询打卡信息配置")
    @GetMapping("/getClockInInfo/{projectId}")
    public AjaxResult getClockInInfo(@PathVariable Long projectId) {
        return success(miniSalaryService.getClockInInfo(projectId));
    }

    @Operation(description = "获取考勤列表")
    @GetMapping("/selectAttendanceList")
    public TableDataInfo selectAttendanceList(CldAttendanceDto cldAttendanceDto) {
        return getMiniDataTable(miniSalaryService.selectAttendanceList(cldAttendanceDto));
    }

    @Operation(description = "获取异常考勤列表")
    @GetMapping("/selectAbnormalAttendanceList")
    public TableDataInfo selectAbnormalAttendanceList(CldAttendanceDto cldAttendanceDto) {
        startPage();
        List<CldAttendanceVo> list = miniSalaryService.selectAbnormalAttendanceList(cldAttendanceDto);
        return getMiniDataTable(list);
    }

    @Operation(description = "判断是否可打卡")
    @PutMapping("/isCheckIn/{attendanceId}")
    public AjaxResult isCheckIn(@PathVariable Long attendanceId, @RequestParam(name = "lng", required = true) BigDecimal lng,
                                @RequestParam(name = "lat", required = true) BigDecimal lat) {

        return success(miniSalaryService.isCheckIn(attendanceId, lng, lat));
    }

    @Operation(description = "打卡提交")
    @Log(title = "打卡提交", businessType = BusinessType.chekin)
    @PutMapping("/checkIn")
    public AjaxResult checkIn(@RequestBody CldAttendanceDto cldAttendanceDto) {
        return toAjax(miniSalaryService.checkIn(cldAttendanceDto));
    }

    @Operation(description = "查看出勤人员")
    @GetMapping("/selectAttStaff")
    public AjaxResult selectAttStaff(CldAttendance cldAttendance) {
        return success(miniSalaryService.selectAttStaff(cldAttendance));
    }

    @Operation(description = "编辑出勤人员")
    @PostMapping("/editAttStaff")
    public AjaxResult editAttStaff(@RequestBody AttStaffInfo attStaffInfo) {
        return toAjax(miniSalaryService.editAttStaff(attStaffInfo));
    }


    @Operation(description = "获取日历")
    @GetMapping("/selectHolidays")
    public AjaxResult selectHolidays(CldCalendar cldCalendar) {
        return success(cldCalendarService.selectCldCalendarList(cldCalendar));
    }
}
